//
//  SingerInforViewController.m
//  LuckyRadio
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "SingerInforViewController.h"
#import "SingerInforCollectionViewCell.h"
#import "GetConnection.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface SingerInforViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic, retain)NSMutableArray *arrayData;

@property (nonatomic, retain)UICollectionView *collectionView;

@property (nonatomic, retain)UIImageView *imageView_singer;

@end

@implementation SingerInforViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *btn_back = [UIButton buttonWithType:UIButtonTypeCustom];
    btn_back.frame = CGRectMake(0, 0, 30, 30);
    btn_back.backgroundColor = [UIColor orangeColor];
    [btn_back setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [btn_back addTarget:self action:@selector(btn_back_Action:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn_back];
    
    [self createSubviews];
}
- (void)btn_back_Action:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)createSubviews
{
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
    
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    flowLayout.minimumInteritemSpacing = 0;
    
    flowLayout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];
    
    self.collectionView.delegate = self;
    
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[SingerInforCollectionViewCell class] forCellWithReuseIdentifier:@"cellSingerinfor"];
    
    self.collectionView.contentInset = UIEdgeInsetsMake(220, 0, 0, 0);
    
    self.imageView_singer = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    NSURL *url = [NSURL URLWithString:self.singerDetailModel.pic_url];
    [self.imageView_singer sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    self.imageView_singer.contentMode = UIViewContentModeScaleAspectFill;
    
    [self.collectionView addSubview:self.imageView_singer];
    [_imageView_singer release];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.view.frame.size.width, 300);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //刚开始y的偏移量初始值就是-220
    //    NSLog(@"y1 === %f",scrollView.contentOffset.y);
    CGFloat y = scrollView.contentOffset.y ;//第一次是-220
    //    NSLog(@"y2 === %f",y);
    if (y < - 220) {
        CGRect frame = self.imageView_singer.frame;
        frame.origin.y = y;//imageView的frame是不断往上偏移
        frame.size.height =  -y;//tablview向下偏移了多少,高度就增加多少
        self.imageView_singer.frame = frame;
    }
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SingerInforCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellSingerinfor" forIndexPath:indexPath];
    return cell;
}
- (void)connection
{
    NSString *str = [NSString stringWithFormat:@" http://api.dongting.com/song/singer/%@?detail=true&app=ttpod&v=v8.1.1.2015110616&user_id=0&mid=iPhone5S&f=f234&s=s310&imsi=&hid=&splus=9.1&active=1&net=2&openudid=e97c1f17f916efa173065a10152c7506e65b60f7&idfa=5FBD2BF5-1484-4C9B-A138-4D9CE22EADB5&utdid=VkKezJUW5SwDAGga0yzrZnyO&alf=700606&bundle_id=com.ttpod.music&latitude=38.89680989464323&longtitude=121.5286713817766",self.singerDetailModel.singer_id];
    [GetConnection startGETConnection:str parmaters:nil connectionBlock:^(id responseObject) {
        NSDictionary *dic = responseObject;
        NSDictionary *singerInfor = [dic objectForKey:@"data"];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
